const bcrypt = require('bcryptjs');

class Password {
  constructor(value) {
    this.value = value;
  }

  static async hash(password) {
    const salt = await bcrypt.genSalt();
    const hashedPassword = await bcrypt.hash(password, salt);
    return new Password(hashedPassword);
  }

  static fromHashed(password) {
    return new Password(password);
  }

  async compare(password) {
    return await bcrypt.compare(password, this.value);
  }

  getValue() {
    return this.value;
  }
}

module.exports = Password;
